package com.vecspace.msoffice;

import com.vecspace.exception.HException;
import com.vecspace.utils.Assert;

/**
 * 
 * @version: 1.0
 * @author: wanghua
 */
public class CellRow {
	private int columnCount;
	private CellValue[] cells;
	public CellRow(int columnCount) {
		this.columnCount = columnCount;
		cells = new CellValue[this.columnCount];
	}
	
	/**扩展列
	 * 
	 * @param newColumnCount 追加的列数
	 * @throws HException 
	 * @author: wanghua
	 */
	public void appendColumns(int newColumnCount) throws HException {
		Assert.throwz(newColumnCount > 0, "newColumnCount必须大于0");
		
		CellValue[] newCells = new CellValue[columnCount + newColumnCount];
		
        System.arraycopy(cells,0,newCells, 0, cells.length);
        
        this.columnCount += newColumnCount;
        
        this.cells = newCells;
	}
	
	public CellValue getValue(int columnIndex) {
		return cells[columnIndex];
	}
	
	/**返回单元格的值（统一转为字符串返回），可能返回null。
	 * 
	 * @param columnIndex
	 * @return 
	 * @author: wanghua
	 */
	public String getText(int columnIndex) {
		CellValue cellValue = cells[columnIndex];
		if(cellValue == null)return null;
		else return cellValue.getStringValue();
	}
	
	public void setValue(int columnIndex, CellValue value) {
		cells[columnIndex] = value;
	}
	
	public void setValue(int columnIndex, String value) {
		if(cells[columnIndex] == null) {
			cells[columnIndex] = new CellValue(-1, -1);
		}
		cells[columnIndex].setValue(value);
	}

	public void setColumnCount(int columnCount) {
		this.columnCount = columnCount;
	}
	
	
}
